package com.javabasic.algorithm.leetcode;

public class MaximumDepthofBinaryTree {

    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        return getDepth(root,1);
    }

    public int getDepth(TreeNode treeNode,int len) {
        if (treeNode.left == null && treeNode.right == null) return len;
        int Llen = 0, Rlen = 0;
        if (treeNode.left != null) Llen = getDepth(treeNode.left,len+1);
        if (treeNode.right != null) Rlen = getDepth(treeNode.right,len+1);
        return Math.max(Llen,Rlen);

    }
}
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */